package com.smartrobot.smartrobot.activity;

import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.assist.FailReason;
import com.nostra13.universalimageloader.core.listener.ImageLoadingListener;
import com.nostra13.universalimageloader.core.listener.ImageLoadingProgressListener;
import com.smartrobot.smartrobot.Common.Common;
import com.smartrobot.smartrobot.R;
import com.smartrobot.smartrobot.util.ImageLoaderApi;
import com.smartrobot.smartrobot.view.SmartPhotoView;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.View;
import android.view.WindowManager;
import android.widget.ProgressBar;

public class ShowBigPicActivity extends Activity {
	
	SmartPhotoView photoView;
	ImageLoader imageLoader;
    ProgressBar progress;



	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
        if(savedInstanceState != null){
            throw new NullPointerException();
        }
		setContentView(R.layout.page_show_big_pic);

        WindowManager.LayoutParams lp=getWindow().getAttributes();
        lp.dimAmount=0.8f;
        getWindow().setAttributes(lp);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
		
		init();
	}
	
	@SuppressLint("NewApi") void init(){
		photoView = (SmartPhotoView)findViewById(R.id.smartPhotoView);
        progress = (ProgressBar)findViewById(R.id.big_pic_progress);

		imageLoader = ImageLoader.getInstance();
		
		Intent intent = this.getIntent();
		
		imageLoader.displayImage(Common.baseUrl+intent.getStringExtra("url"), photoView, ImageLoaderApi.getActiveBigPicOptions()
		,new ImageLoadingListener() {
			
			@Override
			public void onLoadingStarted(String arg0, View arg1) {

                progress.setVisibility(View.VISIBLE);
                photoView.setVisibility(View.GONE);
                System.out.println("加载开始");
			}
			
			@Override
			public void onLoadingFailed(String arg0, View arg1, FailReason arg2) {
			}
			
			@Override
			public void onLoadingComplete(String arg0, View arg1, Bitmap arg2) {
                progress.setVisibility(View.GONE);
				photoView.setVisibility(View.VISIBLE);
			}
			
			@Override
			public void onLoadingCancelled(String arg0, View arg1) {
				System.out.println("加载取消");
			}
		}
		,new ImageLoadingProgressListener() {//在这里添加监听
			
			public void onProgressUpdate(String imageUri, View view, int current, int total) {
				
				System.out.println("当前进度："+current +"  "+ total);

                progress.setMax(total);
                progress.setProgress(current);
				
				
			}
		});
		photoView.setVisibility(View.VISIBLE);
		photoView.setCloseActivity(this);
		

	}


	public void onClick(View v) {
		
		System.out.println("关闭程序");
		this.finish();
		
	}
	
	//关闭
	protected void onDestroy() {
		
		super.onDestroy();
	}


	
	
}
